package com.lhkj.ct.meta.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.mybatis.extension.service.impl.IServiceImpl;
import com.lhkj.ct.meta.admin.model.entity.TblOperationLog;
import com.lhkj.ct.meta.admin.service.OperationLogService;
import com.lhkj.ct.meta.admin.mapper.SysOperationLogMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class OperationLogServiceImpl extends IServiceImpl<SysOperationLogMapper, TblOperationLog> implements OperationLogService {

    @Override
    public IPage<TblOperationLog> selectOperationLogPage(TblOperationLog operationLog, PageQuery pageQuery) {
        LambdaQueryWrapper<TblOperationLog> queryWrapper = new LambdaQueryWrapper<TblOperationLog>()
                .like(StringUtils.isNotBlank(operationLog.getTitle()), TblOperationLog::getTitle, operationLog.getTitle())
                .like(StringUtils.isNotBlank(operationLog.getOperatorName()), TblOperationLog::getOperatorName, operationLog.getOperatorName())
                .eq(Objects.nonNull(operationLog.getActionType()), TblOperationLog::getActionType, operationLog.getActionType())
                .eq(Objects.nonNull(operationLog.getOperatorType()), TblOperationLog::getOperatorType, operationLog.getOperatorType())
                .eq(Objects.nonNull(operationLog.getStatus()), TblOperationLog::getStatus, operationLog.getStatus())
                .orderByDesc(TblOperationLog::getCreateTime);
        return getBaseMapper().selectPage(generatePage(pageQuery), queryWrapper);
    }

    @Override
    public void cleanOperationLog() {
        getBaseMapper().delete(new QueryWrapper<>());
    }
}
